package com.ck.demo;

import lombok.Data;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

public class ListDemo {

    public static void main(String[] args) {

        //手机中的数据
        List<User> mList = createUser();
        //SD卡中的数据
        List<User> sdList = createUser2();

        System.out.println("手机中的数据:"+mList);
        System.out.println("SD卡中的数据:"+sdList);

        mList.forEach(o1 -> sdList.forEach(o2 -> System.out.println(o1.equals(o2))));

    }

    /**
     * 手机中的数据
     * @return
     */
    private static List<User> createUser(){
        List<User> userList = new ArrayList<>();
        //用户1
        User user = new User();
        user.setName("li");
        user.setPhontList(createPhone1());
        userList.add(user);
        //用户2
        user = new User();
        user.setName("li");
        user.setPhontList(createPhone2());
        userList.add(user);
        return userList;
    }

    /**
     * SD卡中的数据
     * @return
     */
    private static List<User> createUser2(){
        List<User> userList = new ArrayList<>();
        //用户1
        User user = new User();
        user.setName("li");
        user.setPhontList(createPhone3());
        userList.add(user);

        user = new User();
        user.setName("li");
        user.setPhontList(createPhone1());
        userList.add(user);

        user = new User();
        user.setName("li");
        user.setPhontList(createPhone4());
        userList.add(user);

        return userList;
    }

    private static List<Phone> createPhone1(){
        List<Phone> phoneList = new ArrayList<>();
        Phone phone = new Phone();
        phone.setNum("138");
        phoneList.add(phone);
        phone = new Phone();
        phone.setNum("134");
        phoneList.add(phone);
        phone = new Phone();
        phone.setNum("132");
        phoneList.add(phone);
        return phoneList;
    }

    private static List<Phone> createPhone4(){
        List<Phone> phoneList = new ArrayList<>();
        Phone phone = new Phone();
        phone.setNum("132");
        phoneList.add(phone);
        phone = new Phone();
        phone.setNum("134");
        phoneList.add(phone);
        phone = new Phone();
        phone.setNum("138");
        phoneList.add(phone);
        return phoneList;
    }


    private static List<Phone> createPhone2(){
        List<Phone> phoneList = new ArrayList<>();
        Phone phone = new Phone();
        phone.setNum("132");
        phoneList.add(phone);
        phone = new Phone();
        phone.setNum("136");
        phoneList.add(phone);
        return phoneList;
    }

    private static List<Phone> createPhone3(){
        List<Phone> phoneList = new ArrayList<>();
        Phone phone = new Phone();
        phone.setNum("134");
        phoneList.add(phone);
        phone = new Phone();
        phone.setNum("136");
        phoneList.add(phone);
        return phoneList;
    }
}



@Data
class User{
    private String name;
    private List<Phone> phontList;

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (!(o instanceof User)) {
            return false;
        }
        User user = (User) o;
        return Objects.equals(getName(), user.getName()) &&
                Objects.equals(getPhontList(), user.getPhontList());
    }

    @Override
    public int hashCode() {
        return Objects.hash(getName(), getPhontList());
    }
}

@Data
class Phone{
    private String num;

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (!(o instanceof Phone)) {
            return false;
        }
        Phone phone = (Phone) o;
        return Objects.equals(getNum(), phone.getNum());
    }

    @Override
    public int hashCode() {
        return Objects.hash(getNum());
    }
}


